/**
 * java多线程模式
 * @author andy.rong
 * Q 7-5
 */

package com.myjavalab.thread;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class ThreadPerMessagePatternGUIButton {

	public static void main(String[] args) {
		new MyFrame();
	}
}


class MyFrame extends JFrame implements ActionListener {

	private static final long serialVersionUID = 15654L;


	public MyFrame() {
		super("MyFrame");
		getContentPane().setLayout(new FlowLayout());
		getContentPane().add(new JLabel("Thread Per Message Sample"));
		JButton button = new JButton("Execute");
		getContentPane().add(button);
		button.addActionListener(this);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		pack();
		setVisible(true);
	}
	

	@Override
	public void actionPerformed(ActionEvent e) {
		Service.service();
	}
}

class Service {
	public static void service() {
		new Thread(){
			public void run() {
				doService();
			}
		}.start();
	}
	
	private static void doService() {
		System.out.println("Service");
		for(int i = 0; i < 50; i++) {
			System.out.print(".");
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				
			}
		}
		System.out.println("done .");
		
	}
}
